package com.hzlx.qualitytasks.controller;

import java.util.List;
import java.io.IOException;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.hzlx.qualitytasks.domain.QualityInspectionTasks;
import com.hzlx.qualitytasks.service.IQualityInspectionTasksService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 质量检验任务（记录IQC/IPQC/FQC全流程）Controller
 * 
 * @author ruoyi
 * @date 2025-07-01
 */
@RestController
@RequestMapping("/quality")
public class QualityInspectionTasksController extends BaseController
{
    @Autowired
    private IQualityInspectionTasksService qualityInspectionTasksService;

    /**
     * 查询质量检验任务（记录IQC/IPQC/FQC全流程）列表
     */
    @RequiresPermissions("quality-service:qualitytasks:list")
    @GetMapping("/qualitytasks/list")
    public TableDataInfo list(QualityInspectionTasks qualityInspectionTasks)
    {
        startPage();
        List<QualityInspectionTasks> list = qualityInspectionTasksService.selectQualityInspectionTasksList(qualityInspectionTasks);
        return getDataTable(list);
    }

    /**
     * 导出质量检验任务（记录IQC/IPQC/FQC全流程）列表
     */
    @RequiresPermissions("quality-service:qualitytasks:export")
    @Log(title = "质量检验任务（记录IQC/IPQC/FQC全流程）", businessType = BusinessType.EXPORT)
    @PostMapping("/qualitytasks/export")
    public void export(HttpServletResponse response, QualityInspectionTasks qualityInspectionTasks)
    {
        List<QualityInspectionTasks> list = qualityInspectionTasksService.selectQualityInspectionTasksList(qualityInspectionTasks);
        ExcelUtil<QualityInspectionTasks> util = new ExcelUtil<QualityInspectionTasks>(QualityInspectionTasks.class);
        util.exportExcel(response, list, "质量检验任务（记录IQC/IPQC/FQC全流程）数据");
    }

    /**
     * 获取质量检验任务（记录IQC/IPQC/FQC全流程）详细信息
     */
    @RequiresPermissions("quality-service:qualitytasks:query")
    @GetMapping(value = "/qualitytasks/{taskId}")
    public AjaxResult getInfo(@PathVariable("taskId") Long taskId)
    {
        return success(qualityInspectionTasksService.selectQualityInspectionTasksByTaskId(taskId));
    }

    /**
     * 新增质量检验任务（记录IQC/IPQC/FQC全流程）
     */
    @RequiresPermissions("quality-service:qualitytasks:add")
    @Log(title = "质量检验任务（记录IQC/IPQC/FQC全流程）", businessType = BusinessType.INSERT)
    @PostMapping("/qualitytasks")
    public AjaxResult add(@RequestBody QualityInspectionTasks qualityInspectionTasks)
    {
        return toAjax(qualityInspectionTasksService.insertQualityInspectionTasks(qualityInspectionTasks));
    }

    /**
     * 修改质量检验任务（记录IQC/IPQC/FQC全流程）
     */
    @RequiresPermissions("quality-service:qualitytasks:edit")
    @Log(title = "质量检验任务（记录IQC/IPQC/FQC全流程）", businessType = BusinessType.UPDATE)
    @PutMapping("/qualitytasks")
    public AjaxResult edit(@RequestBody QualityInspectionTasks qualityInspectionTasks)
    {
        return toAjax(qualityInspectionTasksService.updateQualityInspectionTasks(qualityInspectionTasks));
    }

    /**
     * 删除质量检验任务（记录IQC/IPQC/FQC全流程）
     */
    @RequiresPermissions("quality-service:qualitytasks:remove")
    @Log(title = "质量检验任务（记录IQC/IPQC/FQC全流程）", businessType = BusinessType.DELETE)
	@DeleteMapping("/qualitytasks/{taskIds}")
    public AjaxResult remove(@PathVariable Long[] taskIds)
    {
        return toAjax(qualityInspectionTasksService.deleteQualityInspectionTasksByTaskIds(taskIds));
    }
}
